package com.ht.demo.service.manager;

import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.pojo.bo.system.SysUserBO;
import com.ht.demo.common.util.MD5Util;
import com.ht.demo.dao.domain.system.SysUserDO;
import com.ht.demo.service.constans.SystemConfig;
import com.ht.demo.service.mapper.system.SysUserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author hdengxian
 * @Date 2023/4/11 17:06
 */
@Component
public class TestManager {
    Logger logger = LoggerFactory.getLogger(TestManager.class);

    @Resource
    private SysUserMapper sysUserMapper;

    @Transactional
    public void test() throws AppException {
        Boolean f = false;
        Object point = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            SysUserDO userDO = new SysUserDO();
            userDO.setLoginNo("test1234567");
            userDO.setUserName("test1");
            userDO.setPassWd("test1237");
            userDO.setPassWdMd(MD5Util.passwordMD5(userDO.getPassWd(), SystemConfig.getSecretKey()));
            userDO.setCreateTime(new Date());
            userDO.setDelFlag("0");
            userDO.setUpdateTime(new Date());
            sysUserMapper.insertSysUser(userDO);

            SysUserBO userBO = null;
            userBO.setToken("1");
        } catch (Exception e) {
            logger.info("出现异常 - ", e);
            f = true;
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(point);
        }

        SysUserDO update = new SysUserDO();
        update.setId(1L);
        update.setLoginNo("test1111");
        sysUserMapper.updateSysUserById(update);
        logger.info("继续执行了后续操作-----");

    }
}
